import threading
import time
from concurrent.futures.thread import ThreadPoolExecutor
from sql.sql_conn import Mysql_data
from sql.sql_state import select_pp, dllete_pp, select_gun, insert_duiwu
from tkinter import *
import re


class Data_Pipei(Mysql_data):
    def __init__(self, root):
        super().__init__()
        self.beilu =1
        self.beilu0 = 1.2  # 让0
        self.data_a = []
        self.cuo_ying = 850
        self.cuo_time = 45
        self.root = root
        self.lock = threading.Lock()

    def window(self):
        self.root.title("定制")
        the_width, the_height = self.root.maxsize()
        self.root.geometry('%sx%s' % (int(the_width * 0.7), int(the_height * 0.7)))
        self.root.state("zoomed")
        self.txt_quan = Text(self.root, font=('黑体', 15))
        self.txt_quan.place(relwidth=1, relheight=0.5)
        self.txt_ban = Text(self.root, font=('黑体', 15))
        self.txt_ban.place(relwidth=1, relheight=0.5, rely=0.5)
        # self.txt_cuo = Text(self.root, font=('黑体', 16))
        # self.txt_cuo.place(relwidth=1, relheight=0.2, rely=0.8)

    def data_data(self, bb_tal, fb_tal, bisai_fb_bb_duiwu='bisai_fb_bb_duiwu', nnn=0):

        t1 = time.time() - 10
        bb_data_list = select_pp(bb_tal, t1)
        fb_data_list = select_pp(fb_tal, t1)

        bb_data_list = self.run_sql(bb_data_list)
        fb_data_list = self.run_sql(fb_data_list)

        print(bb_tal, len(bb_data_list))
        print(fb_tal, len(fb_data_list))
        self.bb_name = bb_tal.upper()[:2]#bb_tal.upper()[:2] #'XY'#
        self.fb_name = fb_tal.upper()[:2]
        if len(bb_data_list) != 0 and len(fb_data_list) != 0:
            bb_dllete_sql = dllete_pp(bb_tal)
            fb_dllete_sql = dllete_pp(fb_tal)
            profit = dllete_pp("profit_loss")
            valid = dllete_pp("valid_data")
            self.run_sql(bb_dllete_sql, t1 - 60)
            self.run_sql(fb_dllete_sql, t1 - 60)
            self.run_sql(profit, t1 - 86400)
            self.run_sql(valid, t1 - 86400)
            # 注意
            select_data = select_gun('FB_game_id, BB_game_id', bisai_fb_bb_duiwu)
            # duiwu_data = self.run_sql_2(select_data)
            duiwu_data = self.data_1(nnn, select_data)
            for i in duiwu_data:
                # print(i)
                fb_duiwu_1 = i[0]
                bb_duiwu_1 = i[1]
                for f_data in fb_data_list:
                    if fb_duiwu_1 != f_data[15]:
                        continue
                    for b_data in bb_data_list:
                        # print(bb_duiwu_1, b_data[15])

                        if bb_duiwu_1 != b_data[15]:
                            continue
                        if b_data[7] == f_data[7]:
                            # print("******************************")
                            self.fb_bb_qufeng(b_data, f_data)
                            try:
                                self.corner = b_data[16]
                            except:
                                self.corner = -1



        # time.sleep(2)

    def fb_bb_qufeng(self, bb, fb):

        self.t1 = time.time()
        self.t2 = time.strftime("%X", time.localtime())
        # if bb[14] == fb[14]:
        fb_bb_beili = 0.2
        cuo_da_th = threading.Thread(target=self.data_pipei_daxiao_cuopan, args=(fb, bb))
        cuo_ran_th = threading.Thread(target=self.data_pipei_rang_cuopan, args=(fb, bb))

        # bb 大主  fb 小客
        if fb[13] > fb_bb_beili and bb[10] > fb_bb_beili:
            bb_fb_th = threading.Thread(target=self.bb_fb_pipei, args=(fb, bb,))
            # self.bb_fb_pipei(fb,bb,data_a=[])
            bb_fb_th.start()

        #  fb 大主  bb 小客
        if fb[10] > fb_bb_beili and bb[13] > fb_bb_beili:
            fb_bb_th = threading.Thread(target=self.fb_bb_pipei, args=(fb, bb,))
            # self.fb_bb_pipei(fb, bb, data_a=[])
            fb_bb_th.start()
        #
        if "让" in fb[7] and "让" in bb[7] and "主" not in fb[7] and "客" not in fb[7]:
            cuo_ran_th.start()
        if "大" in fb[7] and "大" in bb[7] and "主" not in fb[7] and "客" not in fb[7]:
            cuo_da_th.start()

    def bb_fb_pipei(self, fb, bb):
        fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, fb_pelv2, bb_pelv1, fb_pelv1, bb_pelv2, valid_1, valid_2 = self.name_get(
            bb, fb)

        if "让" not in fb[7] and "让" not in bb[7]:
            if bb[9] == fb[9] and bb[8] == fb[8]:
                fb_type2 = self.fb_name + '·' + fb[11] + str(fb[12]).ljust(6)
                bb_type1 = '  ' + self.bb_name + '·' + bb[8] + str(bb[9]).ljust(6)

                if "全" in fb[7]:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队角  "
                        elif "客" in fb[7]:
                            leibie = "全客队角  "
                        elif '让' in fb[7]:
                            leibie = "全角让球  "
                        else:
                            leibie = "全场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队黄  "
                        elif "客" in fb[7]:
                            leibie = "全客队黄  "
                        else:
                            leibie = "全场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "全主大小  "
                        elif "客" in fb[7]:
                            leibie = "全客大小  "
                        else:
                            leibie = "全场大小  "
                else:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队角  "
                        elif "客" in fb[7]:
                            leibie = "半客队角  "
                        elif '让' in fb[7]:
                            leibie = "半角让球  "
                        else:
                            leibie = "半场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队黄  "
                        elif "客" in fb[7]:
                            leibie = "半客队黄  "
                        else:
                            leibie = "半场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "半主大小  "
                        elif "客" in fb[7]:
                            leibie = "半客大小  "
                        else:
                            leibie = "半场大小  "

                if "黄" not in fb[7]:
                    if valid_2 > self.beilu:
                        # valid = round(float(bb[10]) * float(fb[13]), 4)
                        data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                            int(valid_2 * 1000 - 1000))  # , fb[14]

                        if data1 not in self.data_a:
                            # if int(valid_2 * 1000 - 1000) < 1000:
                            self.data_a.append(data1)
                            print("data_pipei_data_daxiao 001")
                            if "全" in leibie:
                                self.data_write(data1, "quan.txt")
                            else:
                                self.data_write(data1, "ban.txt")


        else:
            if bb[9] == fb[9]:  #: and bb[9] != "0" and fb[12] != "0"
                if bb[9] == "0" and fb[12] == "0" and valid_2 < self.beilu0 :
                    return
                name_zhu = bb[8]
                name_ke = fb[11]
                if fb[8] == fb[5] or fb[11] == fb[5]:
                    name_zhu = "主"
                if bb[11] == bb[6] or bb[8] == bb[6]:
                    name_ke = "客"

                fb_type2 = self.fb_name + '·' + name_ke + str(fb[12]).ljust(6)
                bb_type1 = '  ' + self.bb_name + '·' + name_zhu + str(bb[9]).ljust(6)

                if "全" in fb[7]:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队角  "
                        elif "客" in fb[7]:
                            leibie = "全客队角  "
                        elif '让' in fb[7]:
                            leibie = "全角让球  "
                        else:
                            leibie = "全场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队黄  "
                        elif "客" in fb[7]:
                            leibie = "全客队黄  "
                        else:
                            leibie = "全场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "全主队让  "
                        elif "客" in fb[7]:
                            leibie = "全客队让  "
                        else:
                            leibie = "全场让球  "
                else:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队角  "
                        elif "客" in fb[7]:
                            leibie = "半客队角  "
                        elif '让' in fb[7]:
                            leibie = "半角让球  "
                        else:
                            leibie = "半场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队黄  "
                        elif "客" in fb[7]:
                            leibie = "半客队黄  "
                        else:
                            leibie = "半场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "半主队让  "
                        elif "客" in fb[7]:
                            leibie = "半客队让  "
                        else:
                            leibie = "半场让球  "

                if "黄" not in fb[7]:
                    if valid_2 > self.beilu and fb[11] == fb[6] and bb[8] == bb[5]:
                        # valid = round(float(bb[10]) * float(fb[13]),4)
                        data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                            int(valid_2 * 1000 - 1000))  # , fb[14]
                        if data1 not in self.data_a:
                            # if int(valid_2 * 1000 - 1000) < 1000:
                            self.data_a.append(data1)
                            print("data_pipei_data_rang 004")
                            if "全" in leibie:
                                self.data_write(data1, "quan.txt")
                            else:
                                self.data_write(data1, "ban.txt")

    def fb_bb_pipei(self, fb, bb):
        fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, fb_pelv2, bb_pelv1, fb_pelv1, bb_pelv2, valid_1, valid_2 = self.name_get(
            bb, fb)

        if "让" not in fb[7] and "让" not in bb[7]:

            if bb[9] == fb[9] and bb[8] == fb[8]:

                fb_type1 = self.fb_name + '·' + fb[8] + str(fb[9]).ljust(6)
                bb_type2 = '  ' + self.bb_name + '·' + bb[11] + str(bb[12]).ljust(6)

                if "全" in fb[7]:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队角  "
                        elif "客" in fb[7]:
                            leibie = "全客队角  "
                        elif '让' in fb[7]:
                            leibie = "全角让球  "
                        else:
                            leibie = "全场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队黄  "
                        elif "客" in fb[7]:
                            leibie = "全客队黄  "
                        else:
                            leibie = "全场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "全主大小  "
                        elif "客" in fb[7]:
                            leibie = "全客大小  "
                        else:
                            leibie = "全场大小  "
                else:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队角  "
                        elif "客" in fb[7]:
                            leibie = "半客队角  "
                        elif '让' in fb[7]:
                            leibie = "半角让球  "
                        else:
                            leibie = "半场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队黄  "
                        elif "客" in fb[7]:
                            leibie = "半客队黄  "
                        else:
                            leibie = "半场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "半主大小  "
                        elif "客" in fb[7]:
                            leibie = "半客大小  "
                        else:
                            leibie = "半场大小  "

                if valid_1 > self.beilu:
                    # valid = round(float(fb[10]) * float(bb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                        int(valid_1 * 1000 - 1000))  # , fb[14]
                    if data1 not in self.data_a:
                        # if int(valid_1 * 1000 - 1000) < 1000:

                        self.data_a.append(data1)
                        print("data_pipei_data_daxiao 002")
                        if "全" in leibie:
                            self.data_write(data1, "quan.txt")
                        else:
                            self.data_write(data1, "ban.txt")

        else:
            if bb[9] == fb[9]:  # : and bb[12] != "0" and fb[9] != "0"
                if bb[12] == "0" and fb[9] == "0" and valid_1 < self.beilu0 :
                    return
                name_zhu = fb[8]
                name_ke = bb[11]
                if fb[8] == fb[5] or fb[11] == fb[5]:
                    name_zhu = "主"
                if bb[11] == bb[6] or bb[8] == bb[6]:
                    name_ke = "客"

                fb_type1 = self.fb_name + '·' + name_zhu + str(fb[9]).ljust(6)
                bb_type2 = '  ' + self.bb_name + '·' + name_ke + str(bb[12]).ljust(6)

                if "全" in fb[7]:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队角  "
                        elif "客" in fb[7]:
                            leibie = "全客队角  "
                        elif '让' in fb[7]:
                            leibie = "全角让球  "
                        else:
                            leibie = "全场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "全主队黄  "
                        elif "客" in fb[7]:
                            leibie = "全客队黄  "
                        else:
                            leibie = "全场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "全主队让  "
                        elif "客" in fb[7]:
                            leibie = "全客队让  "
                        else:
                            leibie = "全场让球  "
                else:
                    if "角" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队角  "
                        elif "客" in fb[7]:
                            leibie = "半客队角  "
                        elif '让' in fb[7]:
                            leibie = "半角让球  "
                        else:
                            leibie = "半场角球  "
                    elif "黄" in fb[7]:
                        if "主" in fb[7]:
                            leibie = "半主队黄  "
                        elif "客" in fb[7]:
                            leibie = "半客队黄  "
                        else:
                            leibie = "半场黄牌  "
                    else:
                        if "主" in fb[7]:
                            leibie = "半主队让  "
                        elif "客" in fb[7]:
                            leibie = "半客队让  "
                        else:
                            leibie = "半场让球  "

                if valid_1 > self.beilu and fb[8] == fb[5] and bb[11] == bb[6]:
                    # valid = round(float(fb[10]) * float(bb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                        int(valid_1 * 1000 - 1000))

                    if data1 not in self.data_a:
                        # if int(valid_1 * 1000 - 1000) < 1000:
                        self.data_a.append(data1)
                        print("data_pipei_data_rang 003")
                        if "全" in leibie:
                            self.data_write(data1, "quan.txt")
                        else:
                            self.data_write(data1, "ban.txt")

    def data_pipei_daxiao_cuopan(self, fb, bb):
        beilu_1 = 0.75  # 1
        beilu_2 = 0.7  # 2
        beilu_3 = 0.67  # 3
        beilu_4 = 0.7  # 4
        fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, fb_pelv2, bb_pelv1, fb_pelv1, bb_pelv2, valid_1, valid_2 = self.name_get(
            bb, fb)

        if bb[8] == fb[8]:
            fb_type2 = self.fb_name + '·' + fb[11] + str(fb[12]).ljust(6)
            bb_type1 = '  ' + self.bb_name + '·' + bb[8] + str(bb[9]).ljust(6)

            fb_type1 = self.fb_name + '·' + fb[8] + str(fb[9]).ljust(6)
            bb_type2 = '  ' + self.bb_name + '·' + bb[11] + str(bb[12]).ljust(6)

            if "全" in fb[7]:
                if "角" in fb[7]:
                    if "主" in fb[7]:
                        leibie = "全主队角  "
                    elif "客" in fb[7]:
                        leibie = "全客队角  "
                    elif '让' in fb[7]:
                        leibie = "全角让球  "
                    else:
                        leibie = "全场角球  "
                elif "黄" in fb[7]:
                    if "主" in fb[7]:
                        leibie = "全主队黄  "
                    elif "客" in fb[7]:
                        leibie = "全客队黄  "
                    else:
                        leibie = "全场黄牌  "
                else:
                    if "主" in fb[7]:
                        leibie = "全主大小  "
                    elif "客" in fb[7]:
                        leibie = "全客大小  "
                    else:
                        leibie = "全场大小  "
            else:
                if "角" in fb[7]:
                    if "主" in fb[7]:
                        leibie = "半主队角  "
                    elif "客" in fb[7]:
                        leibie = "半客队角  "
                    elif '让' in fb[7]:
                        leibie = "半角让球  "
                    else:
                        leibie = "半场角球  "
                elif "黄" in fb[7]:
                    if "主" in fb[7]:
                        leibie = "半主队黄  "
                    elif "客" in fb[7]:
                        leibie = "半客队黄  "
                    else:
                        leibie = "半场黄牌  "
                else:
                    if "主" in fb[7]:
                        leibie = "半主大小  "
                    elif "客" in fb[7]:
                        leibie = "半客大小  "
                    else:
                        leibie = "半场大小  "

            if fb[11] == "小" and bb[8] == "大":
                fb_ty_name_1 = re.findall("(...)/.", fb[12])
                bb_ty_name_1 = bb[9]
                bb_ty_name_2 = re.findall("(...)/.", bb[12])  # 9
                fb_ty_name_2 = fb[9]  # 12

                fb_ty_name_3 = re.findall("(.)/...", fb[12])
                bb_ty_name_3 = bb[9]
                bb_ty_name_4 = re.findall("(.)/...", bb[12])  # 9
                fb_ty_name_4 = fb[9]  # 12

                fb_ty_name_5 = re.findall(".../(.)", fb[9])  # 12
                bb_ty_name_5 = bb[12]  # 9
                bb_ty_name_6 = re.findall(".../(.)", bb[9])
                fb_ty_name_6 = fb[12]

                fb_ty_name_7 = re.findall("./(...)", fb[9])  # 12
                bb_ty_name_7 = bb[12]  # 9
                bb_ty_name_8 = re.findall("./(...)", bb[9])
                fb_ty_name_8 = fb[12]


                if bb_ty_name_2 != [] and fb_ty_name_2 == bb_ty_name_2[0]:
                    if valid_1 > beilu_1:
                        # valid = round(float(fb[10]) * float(bb[13]), 4)
                        data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                            int(valid_1 * 1000)), "(+" + str(int(valid_1 * 1000 + 500 - 1000)) + " " + str(
                            int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                        if data1 not in self.data_a:
                            self.data_a.append(data1)
                            if int(valid_1 * 1000) > self.cuo_ying:
                                if int(valid_1 * 1000) > self.cuo_ying and int(
                                        bisai_time) < self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif "半" in leibie:
                                    self.data_write(data1, "cuo.txt")

                if bb_ty_name_4 != [] and fb_ty_name_4 == bb_ty_name_4[0] and bb[9] != "4.5/5":
                    if valid_1 > beilu_2:
                        # valid = round(float(fb[10]) * float(bb[13]), 4)
                        data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                            int(valid_1 * 1000)), "(+" + str(int(bb[13] / 2 * 1000)) + " " + str(
                            int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                        if data1 not in self.data_a:
                            self.data_a.append(data1)
                            if int(valid_1 * 1000) > self.cuo_ying:
                                if int(valid_1 * 1000) > self.cuo_ying and int(
                                        bisai_time) < self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif "半" in leibie:
                                    self.data_write(data1, "cuo.txt")
                #
                if fb_ty_name_5 != [] and fb_ty_name_5[0] == bb_ty_name_5:
                    if valid_1 > beilu_3:
                        # valid = round(float(fb[10]) * float(bb[13]), 4)
                        data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                            int(valid_1 * 1000)), "(+" + str(int(valid_1 / 2 * 1000)) + " " + str(
                            int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                        if data1 not in self.data_a:
                            self.data_a.append(data1)
                            if int(valid_1 * 1000) > self.cuo_ying:
                                if int(valid_1 * 1000) > self.cuo_ying and int(
                                        bisai_time) < self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif "半" in leibie:
                                    self.data_write(data1, "cuo.txt")

                if fb_ty_name_7 != [] and fb_ty_name_7[0] == bb_ty_name_7 and bb[13] > 0.6:
                    if valid_1 > beilu_4:
                        # valid = round(float(fb[10]) * float(bb[13]), 4)
                        data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                            int(valid_1 * 1000)), "(+" + str(int(bb[13] / 2 * 1000)) + " " + str(
                            int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                        if data1 not in self.data_a:
                            self.data_a.append(data1)
                            if int(valid_1 * 1000) > self.cuo_ying:
                                if int(valid_1 * 1000) > self.cuo_ying and int(
                                        bisai_time) < self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                    self.data_write(data1, "cuo.txt")
                                elif "半" in leibie:
                                    self.data_write(data1, "cuo.txt")

                if "黄" not in fb[7]:

                    if fb_ty_name_1 != [] and fb_ty_name_1[0] == bb_ty_name_1 and bb_ty_name_1 != "5":
                        if valid_2 > beilu_1:
                            # valid = round(float(bb[10]) * float(fb[13]), 4)
                            data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                                int(valid_2 * 1000)), "(+" + str(int(valid_2 * 1000 + 500 - 1000)) + " " + str(
                                int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                            if data1 not in self.data_a:
                                self.data_a.append(data1)
                                if int(valid_2 * 1000) > self.cuo_ying:
                                    if int(valid_2 * 1000) > self.cuo_ying and int(
                                            bisai_time) <= self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif "半" in leibie:
                                        self.data_write(data1, "cuo.txt")

                    if fb_ty_name_3 != [] and fb_ty_name_3[0] == bb_ty_name_3 and fb[9] != "4.5/5":
                        if valid_2 > beilu_2:
                            # valid = round(float(bb[10]) * float(fb[13]), 4)
                            data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                                int(valid_2 * 1000)), "(+" + str(int(fb[13] / 2 * 1000)) + " " + str(
                                int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                            if data1 not in self.data_a:
                                self.data_a.append(data1)
                                if int(valid_2 * 1000) > self.cuo_ying:
                                    if int(valid_2 * 1000) > self.cuo_ying and int(
                                            bisai_time) < self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif "半" in leibie:
                                        self.data_write(data1, "cuo.txt")

                    if bb_ty_name_6 != [] and fb_ty_name_6 == bb_ty_name_6[0]:
                        if valid_2 > beilu_3:
                            # valid = round(float(bb[10]) * float(fb[13]), 4)
                            data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                                int(valid_2 * 1000)), "(+" + str(int(valid_2 / 2 * 1000)) + " " + str(
                                int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                            if data1 not in self.data_a:
                                self.data_a.append(data1)
                                if int(valid_2 * 1000) > self.cuo_ying:
                                    if int(valid_2 * 1000) > self.cuo_ying and int(
                                            bisai_time) < self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif "半" in leibie:
                                        self.data_write(data1, "cuo.txt")

                    if bb_ty_name_8 != [] and fb_ty_name_8 == bb_ty_name_8[0] and fb[13] > 0.6:
                        if valid_2 > beilu_4:
                            # valid = round(float(bb[10]) * float(fb[13]), 4)
                            data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                                int(valid_2 * 1000)), "(+" + str(int(fb[13] / 2 * 1000)) + " " + str(
                                int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                            if data1 not in self.data_a:
                                self.data_a.append(data1)
                                if int(valid_2 * 1000) > self.cuo_ying:
                                    if int(valid_2 * 1000) > self.cuo_ying and int(
                                            bisai_time) < self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif "半" in leibie:
                                        self.data_write(data1, "cuo.txt")

                if '/' not in bb[9]and '/' not in fb[9]:
                    # bb_ty_name_9 = bb[9]        # bb大
                    # fb_ty_name_9 = bb[9] + '.5' # fb

                    # fb_ty_name_9 = fb[9]                # fb   大
                    # bb_ty_name_9 = fb[9] + '.5'       # bb

                    if '.' in bb[9]:
                        fb_ty_name_9 = int(float(bb[9]) + 0.5)  # fb
                    else:
                        fb_ty_name_9 = bb[9] + '.5'
                    if '.' in fb[9]:
                        bb_ty_name_9 = int(float(fb[9]) + 0.5)  # fb
                    else:
                        bb_ty_name_9 = fb[9] + '.5'

                    if "黄" not in fb[7]:
                        if fb[12] == str(fb_ty_name_9):
                            if valid_2 > beilu_3:
                                # valid = round(float(bb[10]) * float(fb[13]), 4)
                                data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                                    int(valid_2 * 1000)), "(+" + str(int(fb[13] * 1000)) + " " + str(
                                    int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                                if data1 not in self.data_a:
                                    self.data_a.append(data1)
                                    if int(valid_2 * 1000) > self.cuo_ying:
                                        if int(valid_2 * 1000) > self.cuo_ying and int(
                                                bisai_time) < self.cuo_time and "全" in leibie:
                                            self.data_write(data1, "cuo.txt")
                                        elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                            self.data_write(data1, "cuo.txt")
                                        elif "半" in leibie:
                                            self.data_write(data1, "cuo.txt")

                    if bb[12] == str(bb_ty_name_9):
                        if valid_1 > beilu_3:
                            # valid = round(float(fb[10]) * float(bb[13]), 4)
                            data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                                int(valid_1 * 1000)), "(+" + str(int(bb[13] * 1000)) + " " + str(
                                int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                            if data1 not in self.data_a:
                                self.data_a.append(data1)
                                if int(valid_1 * 1000) > self.cuo_ying:
                                    if int(valid_1 * 1000) > self.cuo_ying and int(
                                            bisai_time) < self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                        self.data_write(data1, "cuo.txt")
                                    elif "半" in leibie:
                                        self.data_write(data1, "cuo.txt")

    def data_pipei_rang_cuopan(self, fb, bb):
        beilu_r_1 = 0.75
        beilu_r_2 = 0.7
        beilu_r_3 = 0.67
        beilu_r_4 = 0.7
        fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, fb_pelv2, bb_pelv1, fb_pelv1, bb_pelv2, valid_1, valid_2 = self.name_get(
            bb, fb)
        name_zhu = fb[8]
        name_ke = bb[11]
        if fb[8] == fb[5] or fb[11] == fb[5]:
            name_zhu = "主"
        if bb[11] == bb[6] or bb[8] == bb[6]:
            name_ke = "客"

        fb_type2 = self.fb_name + '·' + name_ke + str(fb[12]).ljust(6)
        bb_type1 = '  ' + self.bb_name + '·' + name_zhu + str(bb[9]).ljust(6)

        fb_type1 = self.fb_name + '·' + name_zhu + str(fb[9]).ljust(6)
        bb_type2 = '  ' + self.bb_name + '·' + name_ke + str(bb[12]).ljust(6)

        if "全" in fb[7]:
            if "角" in fb[7]:
                if "主" in fb[7]:
                    leibie = "全主队角  "
                elif "客" in fb[7]:
                    leibie = "全客队角  "
                elif '让' in fb[7]:
                    leibie = "全角让球  "
                else:
                    leibie = "全场角球  "
            elif "黄" in fb[7]:
                if "主" in fb[7]:
                    leibie = "全主队黄  "
                elif "客" in fb[7]:
                    leibie = "全客队黄  "
                else:
                    leibie = "全场黄牌  "
            else:
                if "主" in fb[7]:
                    leibie = "全主让球  "
                elif "客" in fb[7]:
                    leibie = "全客让球  "
                else:
                    leibie = "全场让球  "
        else:
            if "角" in fb[7]:
                if "主" in fb[7]:
                    leibie = "半主队角  "
                elif "客" in fb[7]:
                    leibie = "半客队角  "
                elif '让' in fb[7]:
                    leibie = "半角让球  "
                else:
                    leibie = "半场角球  "
            elif "黄" in fb[7]:
                if "主" in fb[7]:
                    leibie = "半主队黄  "
                elif "客" in fb[7]:
                    leibie = "半客队黄  "
                else:
                    leibie = "半场黄牌  "
            else:
                if "主" in fb[7]:
                    leibie = "半主让球  "
                elif "客" in fb[7]:
                    leibie = "半客让球  "
                else:
                    leibie = "半场让球  "

        fb_r_name_1 = re.findall("\+(...)/.", fb[9])
        bb_r_name_1 = bb[12][1:]
        bb_r_name_2 = re.findall("\+(...)/.", bb[9])
        fb_r_name_2 = fb[12][1:]

        fb_r_name_3 = re.findall("\+(.)/...", fb[9])
        bb_r_name_3 = bb[12][1:]
        bb_r_name_4 = re.findall("\+(.)/...", bb[9])
        fb_r_name_4 = fb[12][1:]

        fb_r_name_5 = re.findall("-.../(.)", fb[9])
        bb_r_name_5 = bb[12][1:]
        bb_r_name_6 = re.findall("-.../(.)", bb[9])
        fb_r_name_6 = fb[12][1:]

        fb_r_name_7 = re.findall("-./(...)", fb[9])
        bb_r_name_7 = bb[12][1:]
        bb_r_name_8 = re.findall("-./(...)", bb[9])
        fb_r_name_8 = fb[12][1:]

        if fb[8] == fb[5] and bb[8] == bb[5] and "0/0.5" not in bb[9] and "0/0.5" not in fb[9]:
            if fb_r_name_1 != [] and fb_r_name_1[0] == bb_r_name_1:
                if valid_1 > beilu_r_1:
                    # valid = round(float(fb[10]) * float(bb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                        int(valid_1 * 1000)), "(+" + str(int(valid_1 * 1000 + 500 - 1000)) + " " + str(
                        int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_1 * 1000) > self.cuo_ying:
                            if int(valid_1 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif bb_r_name_2 != [] and fb_r_name_2 == bb_r_name_2[0]:
                if valid_2 > beilu_r_1:
                    # valid = round(float(bb[10]) * float(fb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                        int(valid_2 * 1000)), "(+" + str(int(valid_2 * 1000 + 500 - 1000)) + " " + str(
                        int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_2 * 1000) > self.cuo_ying:
                            if int(valid_2 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif fb_r_name_3 != [] and fb_r_name_3[0] == bb_r_name_3 and fb[10] > 0.6:
                if valid_1 > beilu_r_2:
                    # valid = round(float(fb[10]) * float(bb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                        int(valid_1 * 1000)), "(+" + str(int(fb[10] / 2 * 1000)) + " " + str(
                        int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_1 * 1000) > self.cuo_ying:
                            if int(valid_1 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif bb_r_name_4 != [] and fb_r_name_4 == bb_r_name_4[0] and bb[10] > 0.6:
                if valid_2 > beilu_r_2:
                    # valid = round(float(bb[10]) * float(fb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                        int(valid_2 * 1000)), "(+" + str(int(bb[10] / 2 * 1000)) + " " + str(
                        int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_2 * 1000) > self.cuo_ying:
                            if int(valid_2 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif fb_r_name_5 != [] and fb_r_name_5[0] == bb_r_name_5 and "+" in bb_r_name_5:
                if valid_1 > beilu_r_3:
                    # valid = round(float(fb[10]) * float(bb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                        int(valid_1 * 1000)), "(+" + str(int(valid_1 / 2 * 1000)) + " " + str(
                        int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_1 * 1000) > self.cuo_ying:
                            if int(valid_1 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif bb_r_name_6 != [] and fb_r_name_6 == bb_r_name_6[0] and "+" in fb_r_name_6:
                if valid_2 > beilu_r_3:
                    # valid = round(float(bb[10]) * float(fb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                        int(valid_2 * 1000)), "(+" + str(int(valid_2 / 2 * 1000)) + " " + str(
                        int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_2 * 1000) > self.cuo_ying:
                            if int(valid_2 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif fb_r_name_7 != [] and fb_r_name_7[0] == bb_r_name_7 and bb[13] > 0.6 and "+" in bb_r_name_7:
                if valid_1 > beilu_r_4:
                    # valid = round(float(fb[10]) * float(bb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type1, fb_pelv1, bb_type2, bb_pelv2, "￥:" + str(
                        int(valid_1 * 1000)), "(+" + str(int(bb[13] / 2 * 1000)) + " " + str(
                        int(valid_1 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_1 * 1000) > self.cuo_ying:
                            if int(valid_1 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

            elif bb_r_name_8 != [] and fb_r_name_8 == bb_r_name_8[0] and fb[13] > 0.6 and "+" in fb_r_name_8:
                if valid_2 > beilu_r_4:
                    # valid = round(float(bb[10]) * float(fb[13]), 4)
                    data1 = self.t2, fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, leibie, fb_type2, fb_pelv2, bb_type1, bb_pelv1, "￥:" + str(
                        int(valid_2 * 1000)), "(+" + str(int(fb[13] / 2 * 1000 + 500 - 1000)) + " " + str(
                        int(valid_2 * 1000 - 1000)) + ")"  # , fb[14]
                    if data1 not in self.data_a:
                        self.data_a.append(data1)
                        if int(valid_2 * 1000) > self.cuo_ying:
                            if int(valid_2 * 1000) > self.cuo_ying and int(
                                    bisai_time) < self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif int(bisai_time) > self.cuo_time and "全" in leibie:
                                self.data_write(data1, "cuo.txt")
                            elif "半" in leibie:
                                self.data_write(data1, "cuo.txt")

    def name_get(self, bb, fb):
        # fbliansai = self.fb_name + '·' + str(fb[2][:7])
        # fb_liansai = '{name:<{len}}\t'.format(name=fbliansai, len=18 - len(fbliansai.encode('GBK')) + len(fbliansai))
        fb_liansai = self.fb_name+ '·' + str(fb[2])

        # bbliansai = self.bb_name + '·' + str(bb[2][:7])
        # bb_liansai = '{name:<{len}}\t'.format(name=bbliansai, len=18 - len(bbliansai.encode('GBK')) + len(bbliansai))
        bb_liansai = self.bb_name+ '·' + str(bb[2])

        if 'OD' in fb_liansai:
            bisai_time = str(bb[3]).ljust(4)
        else:
            bisai_time = str(fb[3]).ljust(4)
        bifeng = str(fb[4]).ljust(5)
        # fbduiwu1 = "{:<7}".format(self.fb_name + '·' + fb[5][:5], chr(12288))
        # fb_duiwu1 = '{name:<{len}}\t'.format(name=fbduiwu1, len=14 - len(fbduiwu1.encode('GBK')) + len(fbduiwu1))
        fb_duiwu1 = self.fb_name+ '·' + fb[5]

        # bbduiwu2 = "{:<7}".format(self.bb_name + '·' + bb[6][:5], chr(12288))
        # try:
        #     bb_duiwu2 = '{name:<{len}}\t'.format(name=bbduiwu2, len=14 - len(bbduiwu2.encode('GBK')) + len(bbduiwu2))
        # except:
        #     bb_duiwu2 = '{name:<{len}}\t'.format(name=bbduiwu2, len=13 - len(bbduiwu2.encode('UTF-8')) + len(bbduiwu2))
        bb_duiwu2 = self.bb_name+ '·' + bb[6]

        fb_pelv2 = (" [" + str(fb[13]) + "]").ljust(8)
        bb_pelv1 = (" [" + str(bb[10]) + "]").ljust(8)

        fb_pelv1 = (" [" + str(fb[10]) + "]").ljust(8)
        bb_pelv2 = (" [" + str(bb[13]) + "]").ljust(8)

        valid_1 = round(float(fb[10]) * float(bb[13]), 4)
        valid_2 = round(float(bb[10]) * float(fb[13]), 4)
        return fb_liansai, bb_liansai, bisai_time, bifeng, fb_duiwu1, bb_duiwu2, fb_pelv2, bb_pelv1, fb_pelv1, bb_pelv2, valid_1, valid_2

    def data_write(self, data1, txt):
        print("*******************************", txt)
        valid_sql = insert_duiwu("valid_data")
        profit_sql = insert_duiwu("profit_loss")
        # if txt == "quan.txt":
        #     self.lock.acquire()
        #     da = []
        #     for i in data1:
        #         s = str(i) + " "
        #         self.txt_quan.insert(END, s)
        #         bb = i.strip("\t")  # ￥)]:[(
        #         da.append(bb.strip())
        #     self.txt_quan.insert(END, '\n')
        #     self.txt_quan.see(END)
        #     da.append(str(self.t1))
        #     # print(da)
        #     self.run_sql(valid_sql, da)
        #     self.lock.release()
        #
        # elif txt == "ban.txt":
        #     self.lock.acquire()
        #     da = []
        #     for i in data1:
        #         s = str(i) + " "
        #         bb = i.strip("\t")  # ￥)]:[(
        #         da.append(bb.strip())
        #         self.txt_ban.insert(END, s)
        #     self.txt_ban.insert(END, '\n')
        #     self.txt_ban.see(END)
        #     da.append(str(self.t1))
        #     self.run_sql(valid_sql, da)
        #     # print(da)
        #     self.lock.release()
        #
        # elif txt == "cuo.txt":
        #     self.lock.acquire()
        #     da = []
        #     for i in data1:
        #         # s = str(i) + " "
        #         bb = i.strip("\t")  # ￥)]:[(
        #         da.append(bb.strip())
        #         # self.txt_cuo.insert(END, s)
        #     # self.txt_cuo.insert(END, '\n')
        #     # self.txt_cuo.see(END)
        #     da.append(str(self.t1))
        #
        #     self.run_sql(profit_sql, da)
        #     # print(da)
        #     self.lock.release()

        if int(self.t1) % 120 != 0:
            da = []
            with open(txt, "a+", encoding="utf8") as f:
                for i in data1:
                    f.write(str(i) + " ")
                    bb = i.strip("\t")  # ￥)]:[(
                    da.append(bb.strip())
                f.write("\n")

                f.flush()
            if txt =="cuo.txt":
                da.append(str(self.t1))
                self.run_sql_1(profit_sql, da)
            else:
                da.append(str(self.t1))
                da.append(self.corner)
                self.run_sql_1(valid_sql, da)
        else:
            da = []
            with open(txt, "w+", encoding="utf8") as f:
                for i in data1:
                    f.write(str(i) + " ")
                    bb = i.strip("\t")  # ￥)]:[(
                    da.append(bb.strip())
                f.write("\n")

                f.flush()
            if txt == "cuo.txt":
                da.append(str(self.t1))
                self.run_sql_1(profit_sql, da)
            else:
                da.append(str(self.t1))
                da.append(self.corner)
                self.run_sql_1(valid_sql, da)
        return data1

    def run(self, duiwu,bisai_fb_bb_duiwu):
        while True:
            try:
                # dui = [("bb", "fb",), ("bb_ban", "fb_ban",), ("bb_ran", "fb_ran",), ("bb_ban_ran", "fb_ban_ran",)]
                # dui = [("bc", "bb",), ("bc_ban", "bb_ban",), ("bc_ran", "bb_ran",), ("bc_ban_ran", "bb_ban_ran",)]
                # dui = [("bc", "fb",), ("bc_ban", "fb_ban",), ("bc_ran", "fb_ran",), ("bc_ban_ran", "fb_ban_ran",)]
                with ThreadPoolExecutor(2) as t:
                    for pg in duiwu:
                        # print('*****' ,pg[0], pg[1])
                        t.submit(self.data_data, pg[0], pg[1], bisai_fb_bb_duiwu, 0)
                time.sleep(0.6)
                print("------")
            except Exception as e:
                print(e)
                time.sleep(5)

    def run2(self, duiwu,bisai_fb_bb_duiwu):
        while True:
            try:
                with ThreadPoolExecutor(4) as t:
                    for pg in duiwu:
                        # print('*****' ,pg[0], pg[1])
                        t.submit(self.data_data, pg[0], pg[1], bisai_fb_bb_duiwu, 1)
                time.sleep(0.6)
                print("------")
            except Exception as e:
                print(e)
                time.sleep(5)
    def data_1(self, nnn, select_data):
        if nnn == 0:
            duiwu_data = self.run_sql_2(select_data)
        else:
            duiwu_data = self.run_sql(select_data)
        return duiwu_data
